﻿using System;
using System.CodeDom.Compiler;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Microsoft.VisualBasic;

namespace JH.GladeSharpCodeGenerator
{
    [ComVisible(true)]
    [Guid("47184C41-2B14-4a20-939A-FF69A7E7AE70")]
    public class VBGeneratorFromGlade : GeneratorFromGlade
    {
        private CodeDomProvider _codeProvider = new VBCodeProvider();
        protected override CodeDomProvider CodeProvider
        {
            get { return _codeProvider; }
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (_codeProvider != null)
            {
                _codeProvider.Dispose();
                _codeProvider = null;
            }
        }

        #region Registration

        private static readonly Guid CustomToolGuid = new Guid("{47184C41-2B14-4a20-939A-FF69A7E7AE70}");

        private static readonly Guid Category = new Guid("{164B10B9-B200-11D0-8C61-00A0C91E29D5}");

        private const string CustomToolDescription = "VB.Net code generator for glade";

        [ComRegisterFunction]
        [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "t", 
                Justification = "Signature is imposed by COM")]
        private static void RegisterClass(Type t)
        {
            Register(new Version(9, 0), Category, CustomToolGuid, CustomToolName, CustomToolDescription);
        }

        [ComUnregisterFunction]
        [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "t", 
                Justification = "Signature is imposed by COM")]
        private static void UnregisterClass(Type t)
        {
            Unregister(new Version(9, 0), Category, CustomToolName);
        }

        #endregion
    }
}
